package example.pages;

import net.thucydides.core.annotations.DefaultUrl;
import net.thucydides.core.annotations.findby.FindBy;
import net.thucydides.core.pages.PageObject;

import org.openqa.selenium.WebElement;

@DefaultUrl("http://clickandflirt.com")
public class IndexPage extends PageObject
{

	// Login form
	@FindBy(id = "register-form")
	private WebElement frmReg;
	@FindBy(id = "LoginForm_email")
	private WebElement txtLogin;
	@FindBy(id = "LoginForm_password")
	private WebElement txtPassword;
	@FindBy(id = "login_submit")
	private WebElement btnLogin;

	// Registration form
	@FindBy(id = "UserForm_gender")
	private WebElement selectRegGender;
	@FindBy(id = "UserForm_day")
	private WebElement selectRegAgeDay;
	@FindBy(id = "UserForm_month")
	private WebElement selectRegAgeMonth;
	@FindBy(id = "UserForm_year")
	private WebElement selectRegAgeYear;
	@FindBy(id = "UserForm_email")
	private WebElement txtRegEmail;
	@FindBy(id = "UserForm_password")
	private WebElement txtRegPassword;
	@FindBy(id = "UserForm_location")
	private WebElement txtRegLocation;
	@FindBy(id = "submit_button")
	private WebElement btnRegSubmit;

	// Welcome page
	@FindBy(id = "welcome-popup-loading")
	private WebElement blockWelcomePopup;

	public void login(String login, String pass)
	{
		type_login(login);
		type_password(pass);
		send_login_data();
	}

	public void send_login_data()
	{
		btnLogin.click();
	}

	public void type_password(String pass)
	{
		txtPassword.sendKeys(pass);
	}

	public void type_login(String login)
	{
		txtLogin.sendKeys(login);
	}

	public boolean is_index_page()
	{
		return element(frmReg).isCurrentlyVisible();
	}

	public boolean is_welcome_page()
	{
		return element(blockWelcomePopup).isCurrentlyVisible();
	}

	public void type_registration_password(String p_password)
	{
		element(txtRegPassword).sendKeys(p_password);
	}

	public void type_registration_location(String p_location)
	{
		element(txtRegLocation).clear();
		element(txtRegLocation).sendKeys(p_location);
	}

	/**
	 * Types registration 'email'
	 * 
	 * @param p_email
	 *            User registration email
	 * @return IndexPage instance
	 */
	public void type_registration_email(String p_email)
	{
		element(txtRegEmail).sendKeys(p_email);
	}

	public void set_registration_birth_day(String p_birthDay)
	{
		element(selectRegAgeDay).selectByValue(p_birthDay);
	}

	public void set_registration_birth_month(String p_birthMonth)
	{
		element(selectRegAgeMonth).selectByValue(p_birthMonth);
	}

	public void set_registration_birth_year(String p_birthYear)
	{
		element(selectRegAgeYear).selectByValue(p_birthYear);
	}

	public void set_registration_gender(String p_gender)
	{
		element(selectRegGender).selectByValue(p_gender);
	}

	public void submit_registration_data()
	{
		element(btnRegSubmit).click();
	}
}